package com.zmn.mcc.admin.controller.role.staff;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.request.RequestUtil;
import com.zmn.common.utils.string.StringUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author heguanghua
 * @since 2020/05/11 19:48
 */
@Controller
@RequestMapping("/role/staff/modify/")
public class RoleStaffModifyController extends RoleStaffBaseController {

    /**
     * 移除用户角色
     */
    @RequestMapping("cancel")
    @ResponseBody
    public ResponseDTO cancel(HttpServletRequest request, HttpServletResponse response,
                              @RequestParam(value = "ids", defaultValue = "") String ids) {

        if (StringUtil.isBlank(ids)) {
            return ResponseDTO.fail("未指定要取消对此角色授权的员工");
        }

        String ip = RequestUtil.getRequestIp(request);
        if (StringUtil.isBlank(ids)) {
            return ResponseDTO.fail("未指定要取消对此用户已授权的角色");
        }

        List<String> groups = StringUtil.split(ids, GlobalConsts.SPLITER_DEFAULT, String.class);
        for (String group : groups) {
            List<Integer> idid = StringUtil.split(group, GlobalConsts.SPLITER_UNDERLINE, Integer.class);
            roleStaffBService.deleteRoleByStaffId(idid.get(0), idid.get(1), getLoginStaff(), ip);
        }
        return ResponseDTO.success(null, "操作成功");
    }

}
